// pages/partnercenter/totalreward/totalreward.js
var shihan = require('../../../common/fetch')
var config = require('../../../common/config')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    page_size: 20,
    selllist: [],
    showLoading: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.goodthingask()
  },
  goodthingask: function() {
    var that = this
    shihan.sendRequest(config.reward_list + that.data.page + '-' + that.data.page_size + '.html', 'GET', {})
      .then(function(response) {
        if (response.data.code == 0) {
          that.setData({
            goodthingslabel: response.data.data,
            selllist: that.data.selllist.concat(response.data.data.sh_items),
            page: that.data.page + 1,
            showLoading: false,
            goodthingsflag: true
          })
        } else {
          that.setData({
            hasMore: false,
            showLoading: false
          })
        }
      }, function(error) {
        console.log(error);
      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this
    if (that.data.goodthingsflag) {
      that.setData({
        goodthingsflag: false
      })
    } else {
      this.goodthingask()
    }
  }
})